package self;

import java.util.Scanner;

public class Test_Exception {
    public static void main(String[] args) {
        func();
    }
    // 输入用户名/密码
    private static void func() {
        System.out.print("请输入用户名:");
        String name = new Scanner(System.in).nextLine();
        System.out.print("请输入密码:");
        String pwd = new Scanner(System.in).nextLine();
        try {
            login(name, pwd);
            System.out.println("*****欢迎登录*****");
        }catch (UserNameNFException e){
            System.out.println("用户名输入错误");
            func();
        }catch (PwdNFException e){
            System.out.println("密码输入错误");
            func();
        }
    }
    // 判断用户名/密码是否输入正确
    private static void login(String name, String pwd)
            throws UserNameNFException, PwdNFException {
        if(!"jackiechan".equals(name)){
            throw new UserNameNFException();
        }
        if (!"19540407".equals(pwd)){
            throw new PwdNFException();
        }
    }

}


// 创建密码输入错误异常类
class PwdNFException extends Exception{
    public PwdNFException(){
        super();
    }
    public PwdNFException(String message, Throwable cause, boolean enableSupperssion, boolean writableStackTrace){
        super(message, cause, enableSupperssion, writableStackTrace);
    }
    public PwdNFException(String message, Throwable cause){
        super(message, cause);
    }
    public PwdNFException(String message){
        super(message);
    }
    public PwdNFException(Throwable cause){
        super(cause);
    }
}
// 创建用户名输入错误异常类
class UserNameNFException extends Exception{
    public UserNameNFException(){
        super();
    }
    public UserNameNFException(String massage, Throwable cause, boolean enableSupperssion, boolean writableStackTrace){
        super(massage, cause, enableSupperssion, writableStackTrace);
    }
    public UserNameNFException(String message, Throwable cause){
        super(message, cause);
    }
    public UserNameNFException(String message){
        super(message);
    }
    public UserNameNFException(Throwable cause){
        super(cause);
    }
}